import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMSquRbRPoB6wjuVXZn/hZOMgFvU1rIt\n' +
'bBb3AYCOI3sIuPjBRsb1xvRKcMoWqojWb+EAADT+9AF1ge7NoPLTm7cCAwEAAQ=='

const privateKey = 'MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEAxKq5FtE+gHrCO5Vd\n' +
'mf+Fk4yAW9TWsi1sFvcBgI4jewi4+MFGxvXG9EpwyhaqiNZv4QAANP70AXWB7s2g\n' +
'8tObtwIDAQABAkEAwlUMlf5na19iRKxAlKaIYJdKUvPKvr/hegPTySsq5iun+OII\n' +
'zrLqeXwkoeV9ZXM/iDwA7xObxUImjhzliS6SEQIhAPY3sSJP5ZHod4nHwkJVssB2\n' +
'5CyksUpMcGcFuvYDcLR/AiEAzHsLnw1myKVpctKljzefprAj2LztkC6uchJbhWho\n' +
'HMkCIHkId3K+g8Nt2xVHtR6WsgAacZ/gdaZoXPjHwFge6NBRAiEAr2xga/NzWm+O\n' +
'J5PPtS5jKP2zwx1SMX/a6MIXAjywFQECIQDoqtkLnZV0Kgeb33OMg7KuKkRaFekm\n' +
'9nEeX0oGXVfXyg=='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}
